package com.jgp.third.wx.assist;

import com.jgp.third.wx.model.WxConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2018/6/2
 */
public class RunTimeConfig {
    private static RunTimeConfig single = null;

    private Map<Long, WxConfig> wxConfigMap = new HashMap<>();
    private Map<String, JsApiTicket> jsApiTicketMap = new HashMap<>();
    private Map<String, AccessToken> accessTokenMap = new HashMap<>();

    public static RunTimeConfig getInstance() {
        if (single == null) {
            synchronized (RunTimeConfig.class) {
                if (single == null) {
                    single = new RunTimeConfig();
                }
            }
        }
        return single;
    }

    public void addConfig(WxConfig config){
        wxConfigMap.put(config.getId(),config);
    }

    public WxConfig getConfig(Long configId){
        return wxConfigMap.get(configId);
    }

    public void addJsApiTicket(String appId,JsApiTicket ticket){
        jsApiTicketMap.put(appId,ticket);
    }

    public JsApiTicket getJsApiTicket(String appId){
        return jsApiTicketMap.get(appId);
    }

    public void addAccessToken(String appId,AccessToken token){
        accessTokenMap.put(appId,token);
    }

    public AccessToken getAccessToken(String appId){
        return accessTokenMap.get(appId);
    }

}
